package com.itheima.tanhua.autoconfig;

import com.itheima.tanhua.autoconfig.properties.*;
import com.itheima.tanhua.autoconfig.template.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author Lff
 * @date 2022/3/22
 * 里面有
 * 1.短信发送
 */
//加载properties配置类文件
@EnableConfigurationProperties({
        SmsProperties.class,
        OssProperties.class,
        FaceProperties.class,
        HuanXinProperties.class,
        GreenProperties.class
})
public class TangHuaAutoConfiguration {
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /**
     * 配置短信发送服务
     *
     * @param smsProperties
     * @param restTemplate
     * @return
     */
    @Bean
    public SMSTemplate smsUtils(SmsProperties smsProperties, RestTemplate restTemplate) {
        return new SMSTemplate(restTemplate, smsProperties);
    }

    /**
     * 配置文件上传云服务
     *
     * @param ossProperties
     * @return
     */
    @Bean
    public OssTemplate ossTemplate(OssProperties ossProperties) {
        return new OssTemplate(ossProperties);
    }

    /**
     * 人脸识别组件
     *
     * @param faceProperties
     * @return
     */
    @Bean
    public FaceTemplate faceTemplate(FaceProperties faceProperties) {
        return new FaceTemplate(faceProperties);
    }

    /**
     * 环信即时通讯组件
     *
     * @param huanXinProperties
     * @return
     */
    @Bean
    public HuanXinTemplate huanXinTemplate(HuanXinProperties huanXinProperties) {
        return new HuanXinTemplate(huanXinProperties);
    }


    @Bean
    @ConditionalOnProperty(prefix = "tanhua.green", value = "enable", havingValue = "true")
    public AliyunGreenTemplate aliyunGreenTemplate(GreenProperties properties) {
        return new AliyunGreenTemplate(properties);
    }
}
